import {
  addExternalList,
  addExternalAdd,
  addExternalRemove,
  addExternalListItem,
  addExternalEdit
} from '@/api/demo'

const useDemoStore = defineStore(
  'demo',
  {
    state: () => ({
      addListData: [{id: '11111', userName: '22222', account: '33333'}],
    }),
    actions: {
      addExternalList() {
        return new Promise((resolve, reject) => {
          addExternalList({ userName: '嘉图', currentPage: 1, pageSize: 50 }).then(response => {
            const data = response.data.data.dataList
            this.addListData = data
            resolve()
          }).catch(error => {
            reject(error)
          })
        })
      },
      addExternalAdd(data) {
        return new Promise((resolve, reject) => {
          addExternalAdd(data).then((res) => {
            resolve(res)
          }).catch(error => {
            reject(error)
          })
        })
      },
      addExternalRemove(id) {
        return new Promise((resolve, reject) => {
          addExternalRemove(id).then((res) => {
            resolve(res)
          }).catch(error => {
            reject(error)
          })
        })
      },
      addExternalListItem(id) {
        return new Promise((resolve, reject) => {
          addExternalListItem(id).then(response => {
            resolve(response)
          }).catch(error => {
            reject(error)
          })
        })
      },
      addExternalEdit(data) {
        return new Promise((resolve, reject) => {
          addExternalEdit(data).then((res) => {
            resolve(res)
          }).catch(error => {
            reject(error)
          })
        })
      }
    }
  })

export default useDemoStore
